using UnityEngine;

public class PlayerManager : MonoBehaviour, ISavable
{
    public static PlayerManager Instance { get; private set; }
    public Player Player { get; private set; }
    public int currency;

    private void OnGUI()
    {
        if (GUILayout.Button("增加100金币"))
        {
            currency += 100;
        }
    }

    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
        else
            Destroy(this);
        Player = FindAnyObjectByType<Player>();
    }

    public bool HaveEnoughMoney(int price)
    {
        if (price > currency) return false;
        currency -= price;
        return true;
    }

    public void Load(GameData data)
    {
        currency = data.currency;
    }

    public void Save(ref GameData data)
    {
        data.currency = currency;
    }
}